import request from '@/utils/request'
import type { PaginationParams, PaginationResponse } from '@/hooks/usePagination'
import qs from 'qs'

// 示例：获取用户信息（无超时参数，直接请求）
export function getUserInfo(userId: string) {
  return request.get(`/user/info`, { params: { userId } })
}

// 示例：获取订单详情（需要特殊超时时间，写死在函数内部）
export function getOrderDetail(orderId: string) {
  return request.get(`/order/detail`, { params: { orderId }, timeout: 5000 })
}

// 分页查询用户列表
export function getUserList(params: PaginationParams): Promise<PaginationResponse<{
  id: string
  name: string
  email: string
  role: string
  createdAt: string
}>> {
  return request.get('/user/list', { params })
}

// 分页查询订单列表
export function getOrderList(params: PaginationParams): Promise<PaginationResponse<{
  id: string
  orderNo: string
  amount: number
  status: string
  createdAt: string
}>> {
  return request.get('/order/list', { params })
}

// 分页查询文章列表
export function getArticleList(params: PaginationParams): Promise<PaginationResponse<{
  id: string
  title: string
  content: string
  author: string
  publishDate: string
}>> {
  return request.get('/article/list', { params })
}

// 登录

export function login(): Promise<void> {
  return request.post('/login', qs.stringify({
    loginPortal:1,
    loginMode:'PASSWORD',
    username:'superadmin',
    password:'123456'
  }))
}